diff --git a/README.md b/README.md index dc55c19..d81f2a6 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,11 @@ See changelog and develop branch for not-official features. # Changelog +**-3/11/2018/:** + Hopefully this is the last version that will run on the playstore. You would receive notifications from topics you choose with this build. + Fixed a bug that when activity is destroyed on backgroud and night mode is active, MainActivity background was white instead of gray. + TODO: Add a clean list button in TopicListFragment + **-31/10/2018:** Manage your topics layouts finished. Make communication with FirebaseRealtimeDatabase in order to save user prefered topics. diff --git a/app/build.gradle b/app/build.gradle index 91dfc2e..a86b019 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "com.eagskunst.emmanuel.gamingnews" minSdkVersion 16 targetSdkVersion 26 - versionCode 3 - versionName "1.1" + versionCode 4 + versionName "1.2" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true } diff --git a/app/release/release/app.aab b/app/release/release/app.aab new file mode 100644 index 0000000..bed38e0 Binary files /dev/null and b/app/release/release/app.aab differ diff --git a/app/src/main/java/com/eagskunst/emmanuel/gamingnews/Fragments/SettingsFragment.java b/app/src/main/java/com/eagskunst/emmanuel/gamingnews/Fragments/SettingsFragment.java index 757527f..1c2f509 100644 --- a/app/src/main/java/com/eagskunst/emmanuel/gamingnews/Fragments/SettingsFragment.java +++ b/app/src/main/java/com/eagskunst/emmanuel/gamingnews/Fragments/SettingsFragment.java @@ -3,21 +3,19 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.graphics.Color; -import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.preference.CheckBoxPreference; import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.SwitchPreference; import android.util.Log; -import android.widget.ListView; import com.eagskunst.emmanuel.gamingnews.R; import com.eagskunst.emmanuel.gamingnews.Utility.SharedPreferencesLoader; import com.eagskunst.emmanuel.gamingnews.views.MainActivity; import com.eagskunst.emmanuel.gamingnews.views.SettingsActivity; +import com.google.firebase.messaging.FirebaseMessaging; public class SettingsFragment extends PreferenceFragment { @@ -43,8 +41,9 @@ public void onCreate(Bundle savedInstanceState) { nightmodePreference.setOnPreferenceClickListener(preferenceClickListener("night_mode",nightmodePreference.isChecked())); SwitchPreference disableImagesPreference = (SwitchPreference) findPreference("pref_loadimages"); disableImagesPreference.setOnPreferenceClickListener(preferenceClickListener("load_images",disableImagesPreference.isChecked())); + CheckBoxPreference dailyReminderPreference = (CheckBoxPreference) findPreference("pref_dailynotf"); + dailyReminderPreference.setOnPreferenceClickListener(preferenceClickListener("daily_notf",dailyReminderPreference.isChecked())); Preference manageTopics = findPreference("pref_managetopics"); - manageTopics.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { @@ -70,15 +69,31 @@ private Preference.OnPreferenceClickListener preferenceClickListener(final Strin return new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { - if(isChecked) - sharedPreferences.edit().putBoolean(prefKey,false).apply(); - else - sharedPreferences.edit().putBoolean(prefKey,true).apply(); - if(prefKey.equals("night_mode")) - reloadApp(); - else if(prefKey.equals("load_images")){ - SharedPreferencesLoader.setCanLoadImages(sharedPreferences); + if(prefKey.equals("daily_notf")){ + boolean daily_notf = sharedPreferences.getBoolean(prefKey,false); + if(!daily_notf){ + Log.d(this.getClass().getSimpleName(), "onPreferenceClick: subscribed"); + FirebaseMessaging.getInstance().subscribeToTopic("all"); + sharedPreferences.edit().putBoolean(prefKey,true).commit(); + } + else{ + Log.d(this.getClass().getSimpleName(), "onPreferenceClick: unsubscribed"); + FirebaseMessaging.getInstance().unsubscribeFromTopic("all"); + sharedPreferences.edit().putBoolean(prefKey,false).commit(); + } + } + else{ + if(isChecked) + sharedPreferences.edit().putBoolean(prefKey,false).apply(); + else + sharedPreferences.edit().putBoolean(prefKey,true).apply(); + if(prefKey.equals("night_mode")) + reloadApp(); + else if(prefKey.equals("load_images")){ + SharedPreferencesLoader.setCanLoadImages(sharedPreferences); + } } + return true; } }; diff --git a/app/src/main/java/com/eagskunst/emmanuel/gamingnews/Fragments/TopicListFragment.java b/app/src/main/java/com/eagskunst/emmanuel/gamingnews/Fragments/TopicListFragment.java index d0c696b..9b07f87 100644 --- a/app/src/main/java/com/eagskunst/emmanuel/gamingnews/Fragments/TopicListFragment.java +++ b/app/src/main/java/com/eagskunst/emmanuel/gamingnews/Fragments/TopicListFragment.java @@ -20,6 +20,7 @@ import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; +import android.widget.Toast; import com.eagskunst.emmanuel.gamingnews.R; import com.eagskunst.emmanuel.gamingnews.Utility.SharedPreferencesLoader; @@ -108,10 +109,15 @@ public boolean onOptionsItemSelected(MenuItem item) { */ case android.R.id.home: if (getActivity().getFragmentManager().getBackStackEntryCount() >= 1) { - addTopicsToFirebase(); - subscribeToTopics(); - SharedPreferencesLoader.saveTopics(sharedPreferences.edit(),topicList); - getFragmentManager().popBackStack(); + try{ + addTopicsToFirebase(); + subscribeToTopics(); + SharedPreferencesLoader.saveTopics(sharedPreferences.edit(),topicList); + getFragmentManager().popBackStack(); + }catch (IllegalArgumentException e){ + Toast.makeText(getActivity(),R.string.ilegalargumentfirebase,Toast.LENGTH_SHORT).show(); + e.printStackTrace(); + } return true; }/* Providing topic addition @@ -149,10 +155,23 @@ public void onClick(DialogInterface dialogInterface, int i) { } else if(!editText.getText().toString().isEmpty()){ topicList.set(position,editText.getText().toString()); + if(!text.equalsIgnoreCase(editText.getText().toString())){ + try{ + FirebaseMessaging.getInstance().unsubscribeFromTopic(text.replace(" ","_").toUpperCase()); + }catch(IllegalArgumentException e){ + Toast.makeText(getActivity(),R.string.ilegalargumentfirebase,Toast.LENGTH_SHORT); + e.printStackTrace(); + } + } } else{ topicList.remove(position); - FirebaseMessaging.getInstance().unsubscribeFromTopic(text.replace(" ","_")); + try{ + FirebaseMessaging.getInstance().unsubscribeFromTopic(text.replace(" ","_").toUpperCase()); + }catch(IllegalArgumentException e){ + Toast.makeText(getActivity(),R.string.ilegalargumentfirebase,Toast.LENGTH_SHORT); + e.printStackTrace(); + } } topicsAdapter.notifyDataSetChanged(); dialogInterface.dismiss(); @@ -165,17 +184,16 @@ else if(!editText.getText().toString().isEmpty()){ private void addTopicsToFirebase(){ DatabaseReference database = FirebaseDatabase.getInstance().getReference(); database.child("topics").child(SharedPreferencesLoader.getFirebaseToken(sharedPreferences)).removeValue(); - database.child("topics").child(SharedPreferencesLoader.getFirebaseToken(sharedPreferences)) - .child("lang").setValue(Locale.getDefault().getLanguage()); + DatabaseReference userReference = database.child("topics") + .child(SharedPreferencesLoader.getFirebaseToken(sharedPreferences)).child("subscribedList"); for(int i = 0;i savedNewsList = new ArrayList<>(); List topicList = new ArrayList<>(); @@ -108,6 +119,7 @@ protected void onCreate(Bundle savedInstanceState) { protected void onDestroy() { super.onDestroy(); navigationHistory.clear(); + SharedPreferencesLoader.saveCurrentTime(getUserSharedPreferences().edit()); } @Override diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 4158300..02240cd 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -30,17 +30,18 @@ channel_0 Interfaz pref_interface - Notifications + Notificaciones pref_notification pref_dailynotf Recibe una notificación diaria Marca para un recordatorio diario para ver las noticias. Gestiona los temas - Nos has añadido temas personalizados para recibir notificaciones. Para añadir uno pulsa \'+\' + No has añadido temas personalizados para recibir notificaciones. Para añadir uno pulsa \'+\' Añadir un tema Cambia los temas de los cuales quieres recibir notificaciones CANCELAR AÑADIR + No uses caracteres especiales ni tildes \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 1aa6dec..2d28058 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -8,4 +8,5 @@ #212121 #757575 #BDBDBD + #303030 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c9dd68e..33ce399 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -45,4 +45,5 @@ Change the topics which you want to receive notifications CANCEL add + Don\'t use special characters