push notification switch added
This commit is contained in:
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
@@ -2,6 +2,7 @@ package ch.pizzapp.android.activity;
|
|||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@@ -18,6 +19,7 @@ import android.widget.RelativeLayout;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.afollestad.materialdialogs.MaterialDialog;
|
import com.afollestad.materialdialogs.MaterialDialog;
|
||||||
|
import com.onesignal.OneSignal;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -66,6 +68,7 @@ public class SplashActivity extends BaseActivity {
|
|||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
//DisplayHelper.changeStatusColor();
|
//DisplayHelper.changeStatusColor();
|
||||||
if(NetworkHelper.isNetworkAvailable()){
|
if(NetworkHelper.isNetworkAvailable()){
|
||||||
|
registerNotificationTag();
|
||||||
getStoreList();
|
getStoreList();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@@ -90,6 +93,15 @@ public class SplashActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerNotificationTag(){
|
||||||
|
if(SessionHelper.isFirstTime()) {
|
||||||
|
OneSignal.sendTag(
|
||||||
|
ApiConstants.ONESIGNAL_NOTIFICATION_TAG_KEY,
|
||||||
|
ApiConstants.ONESIGNAL_NOTIFICATION_TAG_VALUE);
|
||||||
|
SessionHelper.setIsFirstTime(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void getStoreList(){
|
private void getStoreList(){
|
||||||
DialogHelper.showLoadingDialog();
|
DialogHelper.showLoadingDialog();
|
||||||
Call<ResponseArray<StoreModel>> call = ApiService.apiInterface.getStoreList();
|
Call<ResponseArray<StoreModel>> call = ApiService.apiInterface.getStoreList();
|
||||||
|
|||||||
@@ -31,4 +31,7 @@ public class ApiConstants {
|
|||||||
public static final String CART_SUBTOTAL = "zwischensumme";
|
public static final String CART_SUBTOTAL = "zwischensumme";
|
||||||
public static final String CART_COMMISSION = "zahlungsgebühr";
|
public static final String CART_COMMISSION = "zahlungsgebühr";
|
||||||
public static final String CART_TOTAL = "total";
|
public static final String CART_TOTAL = "total";
|
||||||
|
|
||||||
|
public static final String ONESIGNAL_NOTIFICATION_TAG_KEY = "notificationAllowed";
|
||||||
|
public static final String ONESIGNAL_NOTIFICATION_TAG_VALUE = "true";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,18 @@ package ch.pizzapp.android.fragment;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v7.widget.SwitchCompat;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
|
|
||||||
import com.afollestad.materialdialogs.DialogAction;
|
import com.afollestad.materialdialogs.DialogAction;
|
||||||
import com.afollestad.materialdialogs.MaterialDialog;
|
import com.afollestad.materialdialogs.MaterialDialog;
|
||||||
|
import com.onesignal.OneSignal;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import butterknife.BindString;
|
import butterknife.BindString;
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
@@ -22,10 +27,12 @@ import ch.pizzapp.android.activity.MyAddressesActivity;
|
|||||||
import ch.pizzapp.android.activity.SplashActivity;
|
import ch.pizzapp.android.activity.SplashActivity;
|
||||||
import ch.pizzapp.android.activity.UpdatePasswordActivity;
|
import ch.pizzapp.android.activity.UpdatePasswordActivity;
|
||||||
import ch.pizzapp.android.activity.UpdateProfileActivity;
|
import ch.pizzapp.android.activity.UpdateProfileActivity;
|
||||||
|
import ch.pizzapp.android.api.ApiConstants;
|
||||||
import ch.pizzapp.android.api.ApiErrorUtils;
|
import ch.pizzapp.android.api.ApiErrorUtils;
|
||||||
import ch.pizzapp.android.api.ApiService;
|
import ch.pizzapp.android.api.ApiService;
|
||||||
import ch.pizzapp.android.api.ResponseObject;
|
import ch.pizzapp.android.api.ResponseObject;
|
||||||
import ch.pizzapp.android.helper.DialogHelper;
|
import ch.pizzapp.android.helper.DialogHelper;
|
||||||
|
import ch.pizzapp.android.helper.NetworkHelper;
|
||||||
import ch.pizzapp.android.helper.SessionHelper;
|
import ch.pizzapp.android.helper.SessionHelper;
|
||||||
import ch.pizzapp.android.helper.SharedPrefsHelper;
|
import ch.pizzapp.android.helper.SharedPrefsHelper;
|
||||||
import ch.pizzapp.android.model.UserModel;
|
import ch.pizzapp.android.model.UserModel;
|
||||||
@@ -47,6 +54,7 @@ public class ProfileFragment extends BaseFragment {
|
|||||||
@BindView(R.id.lastnamePizzalinkInfoLayout) AppInfoView lastnamePizzalinkInfoLayout;
|
@BindView(R.id.lastnamePizzalinkInfoLayout) AppInfoView lastnamePizzalinkInfoLayout;
|
||||||
@BindView(R.id.emailPizzalinkInfoLayout) AppInfoView emailPizzalinkInfoLayout;
|
@BindView(R.id.emailPizzalinkInfoLayout) AppInfoView emailPizzalinkInfoLayout;
|
||||||
@BindView(R.id.phonePizzalinkInfoLayout) AppInfoView phonePizzalinkInfoLayout;
|
@BindView(R.id.phonePizzalinkInfoLayout) AppInfoView phonePizzalinkInfoLayout;
|
||||||
|
@BindView(R.id.enableNotificationsSwitch) SwitchCompat enableNotificationsSwitch;
|
||||||
|
|
||||||
@BindString(R.string.bottom_nav_menu_item_profile) String fragmentTitle;
|
@BindString(R.string.bottom_nav_menu_item_profile) String fragmentTitle;
|
||||||
@BindString(R.string.alert_logout) String logoutAlertText;
|
@BindString(R.string.alert_logout) String logoutAlertText;
|
||||||
@@ -73,6 +81,7 @@ public class ProfileFragment extends BaseFragment {
|
|||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
initViews();
|
initViews();
|
||||||
getCustomerProfile();
|
getCustomerProfile();
|
||||||
|
getNotificationStatus();
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,6 +138,49 @@ public class ProfileFragment extends BaseFragment {
|
|||||||
|
|
||||||
private void initViews(){
|
private void initViews(){
|
||||||
setPizzalinkToolbarFields(false, fragmentTitle);
|
setPizzalinkToolbarFields(false, fragmentTitle);
|
||||||
|
enableNotificationsSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||||
|
setNotificationStatus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getNotificationStatus(){
|
||||||
|
OneSignal.getTags(new OneSignal.GetTagsHandler() {
|
||||||
|
@Override
|
||||||
|
public void tagsAvailable(final JSONObject tags) {
|
||||||
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if(tags != null &&
|
||||||
|
!tags.toString().isEmpty() &&
|
||||||
|
tags.toString().contains(ApiConstants.ONESIGNAL_NOTIFICATION_TAG_KEY)){
|
||||||
|
enableNotificationsSwitch.setChecked(true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
enableNotificationsSwitch.setChecked(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setNotificationStatus(){
|
||||||
|
if(!NetworkHelper.isNetworkAvailable()){
|
||||||
|
DialogHelper.showNoNetworkDialog();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(enableNotificationsSwitch.isChecked()) {
|
||||||
|
OneSignal.sendTag(
|
||||||
|
ApiConstants.ONESIGNAL_NOTIFICATION_TAG_KEY,
|
||||||
|
ApiConstants.ONESIGNAL_NOTIFICATION_TAG_VALUE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
OneSignal.deleteTag(ApiConstants.ONESIGNAL_NOTIFICATION_TAG_KEY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCustomerProfile(){
|
private void getCustomerProfile(){
|
||||||
|
|||||||
@@ -91,6 +91,13 @@ public class SessionHelper {
|
|||||||
//return SharedPrefsHelper.getSelectedStore();
|
//return SharedPrefsHelper.getSelectedStore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setIsFirstTime(boolean isFirstTime){
|
||||||
|
SharedPrefsHelper.setIsFirstTime(isFirstTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isFirstTime(){
|
||||||
|
return SharedPrefsHelper.isFirstTime();
|
||||||
|
}
|
||||||
|
|
||||||
public static void logOut(){
|
public static void logOut(){
|
||||||
setCustomerLoggedIn(false);
|
setCustomerLoggedIn(false);
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ public class SharedPrefsHelper {
|
|||||||
private static final String PREF_KEY_USER_SEEN_CHAMPAGNE_CAMPAIGN = SHARED_PREFS_NAME + "userSeenChampagneCampaign";
|
private static final String PREF_KEY_USER_SEEN_CHAMPAGNE_CAMPAIGN = SHARED_PREFS_NAME + "userSeenChampagneCampaign";
|
||||||
private static final String PREF_KEY_USER_USED_CHAMPAGNE_CAMPAIGN = SHARED_PREFS_NAME + "userUsedChampagneCampaign";
|
private static final String PREF_KEY_USER_USED_CHAMPAGNE_CAMPAIGN = SHARED_PREFS_NAME + "userUsedChampagneCampaign";
|
||||||
private static final String PREF_KEY_USER_SELECTED_STORE = SHARED_PREFS_NAME + "selectedStore";
|
private static final String PREF_KEY_USER_SELECTED_STORE = SHARED_PREFS_NAME + "selectedStore";
|
||||||
|
private static final String PREF_KEY_IS_FIRST_TIME = SHARED_PREFS_NAME + "isFirstTime";
|
||||||
|
|
||||||
private static SharedPreferences sharedPreferences =
|
private static SharedPreferences sharedPreferences =
|
||||||
BaseActivity.currentActivity
|
BaseActivity.currentActivity
|
||||||
@@ -198,6 +199,14 @@ public class SharedPrefsHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void setIsFirstTime(boolean isFirstTime){
|
||||||
|
editor.putBoolean(PREF_KEY_IS_FIRST_TIME, isFirstTime);
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isFirstTime(){
|
||||||
|
return sharedPreferences.getBoolean(PREF_KEY_IS_FIRST_TIME, true);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public static void saveCategoryList(ArrayList<Category> cats){
|
public static void saveCategoryList(ArrayList<Category> cats){
|
||||||
|
|||||||
@@ -187,6 +187,44 @@
|
|||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:background="@color/black"/>
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/enableNotificationsLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/enable_notifications"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:textColor="@color/black"
|
||||||
|
fontPath="fonts/Quicksand-Bold.ttf"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_toLeftOf="@+id/enableNotificationsSwitch"
|
||||||
|
android:layout_toStartOf="@+id/enableNotificationsSwitch"/>
|
||||||
|
|
||||||
|
<android.support.v7.widget.SwitchCompat
|
||||||
|
android:id="@+id/enableNotificationsSwitch"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_centerVertical="true" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="1dp"
|
android:layout_height="1dp"
|
||||||
|
|||||||
@@ -204,9 +204,10 @@
|
|||||||
<string name="my_addresses">Meine Adressen</string>
|
<string name="my_addresses">Meine Adressen</string>
|
||||||
<string name="update_profile">Profil Aktualisieren</string>
|
<string name="update_profile">Profil Aktualisieren</string>
|
||||||
<string name="update_password">Passwort Aktualisieren</string>
|
<string name="update_password">Passwort Aktualisieren</string>
|
||||||
<string name="button_logout">Abmelden</string>
|
<string name="enable_notifications">Benachrichtigungen aktivieren</string>
|
||||||
<string name="change_post_code">Postleitzahl Ändern</string>
|
<string name="change_post_code">Postleitzahl Ändern</string>
|
||||||
<string name="alert_logout">Möchten Sie sich abmelden?</string>
|
<string name="alert_logout">Möchten Sie sich abmelden?</string>
|
||||||
|
<string name="button_logout">Abmelden</string>
|
||||||
<!-- ProfileFragment-->
|
<!-- ProfileFragment-->
|
||||||
|
|
||||||
<!-- UpdateProfilectivity-->
|
<!-- UpdateProfilectivity-->
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ buildscript {
|
|||||||
maven { url 'https://maven.fabric.io/public' }
|
maven { url 'https://maven.fabric.io/public' }
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.1.3'
|
classpath 'com.android.tools.build:gradle:3.1.4'
|
||||||
classpath 'io.fabric.tools:gradle:1.+'
|
classpath 'io.fabric.tools:gradle:1.+'
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
|
|||||||
Reference in New Issue
Block a user