Skip to content

Commit

Permalink
GibQuote v2.6.2
Browse files Browse the repository at this point in the history
** SettingsFragment -> PreferencesFragment (Notice the extra 's')

* QuoteAdapter:
  - Retain the star status in the View too (with the help of isStarred value)

* PreferencesFragment:
  - Categorize Preferences
  - Add a SwitchPreference which would enable/disable QoTD notifications

* SomeBroadReceiver:
  - Disable alarms according to the newly added switch

* UpdaterUtils:
  > "Debluper Mode" -- If App's version isn't present in the released versions,
    Don't check for updates, gib an acknowledgement toast :D

Signed-off-by: a7r3 <arvindultimate7352@gmail.com>
  • Loading branch information
a7r3 committed Jan 1, 2018
1 parent 3fa6d29 commit 82821c8
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 51 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
minSdkVersion 16
targetSdkVersion 27
versionCode 2
versionName "2.6.1"
versionName "2.6.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/arvind/quote/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import com.arvind.quote.database.FavDatabaseHelper;
import com.arvind.quote.fragment.FavQuoteFragment;
import com.arvind.quote.fragment.GibQuoteFragment;
import com.arvind.quote.fragment.SettingsFragment;
import com.arvind.quote.fragment.PreferencesFragment;
import com.arvind.quote.utils.NotificationUtils;
import com.arvind.quote.utils.UpdaterUtils;
import com.mikepenz.aboutlibraries.LibsBuilder;
Expand Down Expand Up @@ -381,7 +381,7 @@ public void switchFragment(MenuItem item) {
fragment = new GibQuoteFragment();
break;
case R.id.preferences_item:
fragment = new SettingsFragment();
fragment = new PreferencesFragment();
break;
case R.id.licenses_item:
setActionBarTitle("Licenses");
Expand Down Expand Up @@ -416,7 +416,7 @@ public void switchFragment(MenuItem item) {

@Override
public boolean onPreferenceStartScreen(PreferenceFragmentCompat preferenceFragmentCompat, PreferenceScreen preferenceScreen) {
SettingsFragment fragment = new SettingsFragment();
PreferencesFragment fragment = new PreferencesFragment();

Bundle args = new Bundle();
args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, preferenceScreen.getKey());
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/arvind/quote/adapter/QuoteAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public void onBindViewHolder(QuoteViewHolder holder, int position) {
holder.quoteTextView.setText(quote.getQuoteText());
holder.authorTextView.setText(quote.getAuthorText());

// If quote was starred in previous session
// Let the star Glow
if(quote.isStarred())
holder.starQuoteView.setImageResource(R.drawable.star_on);
}

@Override
Expand Down Expand Up @@ -81,6 +85,7 @@ public class QuoteViewHolder extends RecyclerView.ViewHolder {
authorTextView = itemView.findViewById(R.id.author_text_view);

starQuoteView = itemView.findViewById(R.id.star_quote_button);

starQuoteView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.CheckBoxPreference;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
Expand All @@ -14,19 +15,21 @@
import com.arvind.quote.MainActivity;
import com.arvind.quote.R;
import com.arvind.quote.utils.SomeBroadReceiver;
import com.takisoft.fix.support.v7.preference.PreferenceCategory;
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers;
import com.takisoft.fix.support.v7.preference.TimePickerPreference;

// A placeholder fragment containing a simple view.
public class SettingsFragment extends PreferenceFragmentCompatDividers {
public class PreferencesFragment extends PreferenceFragmentCompatDividers {

private String TAG = "SettingsFragment";
private String TAG = "PreferencesFragment";
private SharedPreferences sharedPreferences;

// Listen for changes in a SharedPreference
private SharedPreferences.OnSharedPreferenceChangeListener listener;
private ListPreference themePreference;
private CheckBoxPreference fragSwitcherPreference;
private SwitchPreference switchPreference;
private TimePickerPreference qotdTimePref;

private String getThemeSummary() {
Expand All @@ -47,17 +50,22 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
MainActivity.setActionBarTitle("Preferences");
sharedPreferences = getPreferenceManager().getSharedPreferences();

themePreference = (ListPreference) findPreference("THEME_KEY");
PreferenceCategory lookCategory = (PreferenceCategory) findPreference("LOOK_AND_FEEL");

themePreference = (ListPreference) lookCategory.findPreference("THEME_KEY");
themePreference.setSummary(getThemeSummary());

fragSwitcherPreference = (CheckBoxPreference) findPreference("FRAG_SWITCHER_KEY");
fragSwitcherPreference = (CheckBoxPreference) lookCategory.findPreference("FRAG_SWITCHER_KEY");
fragSwitcherPreference.setSummary(getFragSwitcherSummary());

qotdTimePref = (TimePickerPreference) findPreference("QOTD_TIME");
PreferenceCategory qotdCategory = (PreferenceCategory) findPreference("QOTD_CAT");

qotdTimePref = (TimePickerPreference) qotdCategory.findPreference("QOTD_TIME");
qotdTimePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
// Found out that newValue is of the below type.
// Peeked into TimePickerPreference's source
// Trial and error :D
TimePickerPreference.TimeWrapper timeWrapper = (TimePickerPreference.TimeWrapper) newValue;
sharedPreferences.edit()
Expand All @@ -73,6 +81,32 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
}
});

// Preference to determine whether QoTD TimePicker has to be shown
switchPreference = (SwitchPreference) qotdCategory.findPreference("QOTD_ENABLE");
switchPreference.setSummaryOn("You're receiving daily notifications");
switchPreference.setSummaryOff("You're not receiving daily notifications");

// Hide the TimePickerPreference if it's unchecked
if(!switchPreference.isChecked())
qotdTimePref.setVisible(false);

switchPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Boolean isSwitchOn = (Boolean) newValue;
if(isSwitchOn) // show the TimePicker
qotdTimePref.setVisible(true);
else {
// Hide the TimePicker, and Cancel all alarms in the BroadcastReceiver
qotdTimePref.setVisible(false);
Intent notifServiceIntent = new Intent(getContext(), SomeBroadReceiver.class);
notifServiceIntent.setAction(BuildConfig.APPLICATION_ID + ".CANCEL_QOTD");
getContext().sendBroadcast(notifServiceIntent);
}
return true;
}
});

listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
Expand Down
28 changes: 17 additions & 11 deletions app/src/main/java/com/arvind/quote/utils/SomeBroadReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,30 @@ public class SomeBroadReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {

// Create an intent which would call the BroadcastReceiver Again
Intent someIntent = new Intent(context, SomeBroadReceiver.class);
// But this time, with a different action!
someIntent.setAction("com.arvind.quote.SHOW_QUOTE");
// Get System's AlarmManager
alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
// Create a Pending Intent, which would be executed by the AlarmManager
// At the Given Time and Interval
notifPendingIntent = PendingIntent.getBroadcast(context, 0, someIntent, 0);

if (intent.getAction() != null) {
switch (intent.getAction()) {
case "android.intent.action.BOOT_COMPLETED":
case "com.arvind.quote.TIME_SET_BY_USER":
// Create an intent which would call the BroadcastReceiver Again
Intent someIntent = new Intent(context, SomeBroadReceiver.class);
// But this time, with a different action!
someIntent.setAction("com.arvind.quote.SHOW_QUOTE");
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
Log.d(TAG, "Scheduling QoTD Notifications");
// Get System's AlarmManager
alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
// Create a Pending Intent, which would be executed by the AlarmManager
// At the Given Time and Interval
notifPendingIntent = PendingIntent.getBroadcast(context, 0, someIntent, 0);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
// Get the Calendar, we've got to set the time
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
// Set the Time
calendar.set(Calendar.HOUR_OF_DAY, sharedPreferences.getInt("QOTD_HOUR", 0));
calendar.set(Calendar.MINUTE, sharedPreferences.getInt("QOTD_MIN", 0));
calendar.set(Calendar.SECOND, 0);
Log.i(TAG, calendar.getTime().toString());
Log.i(TAG, "QoTD at : " + calendar.getTime().toString());
alarmManager.setRepeating(
AlarmManager.RTC_WAKEUP, // Ctrl+Q please
calendar.getTimeInMillis(), // Time at which intent has to be executed
Expand All @@ -56,6 +57,11 @@ public void onReceive(Context context, Intent intent) {
case "com.arvind.quote.SHOW_QUOTE":
Log.i(TAG, "Waking up Notification Service");
context.startService(new Intent(context, NotificationService.class));
break;
case "com.arvind.quote.CANCEL_QOTD":
Log.i(TAG, "Cancelling QoTD Alarms");
alarmManager.cancel(notifPendingIntent);
break;
default:
break;
}
Expand Down
14 changes: 12 additions & 2 deletions app/src/main/java/com/arvind/quote/utils/UpdaterUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ public void onResponse(JSONArray response) {
int currentVersionPosition;

// Get Position of currentVersion Tag in the tags List
String interVersion = null;
for (currentVersionPosition = 0; currentVersionPosition < response.length(); currentVersionPosition++) {
String interVersion = response
interVersion = response
.getJSONObject(currentVersionPosition)
.getString("ref")
.replaceAll(".*/", "");
Expand All @@ -116,7 +117,16 @@ public void onResponse(JSONArray response) {
}

// If currentVersion is at the End, we're updated
if (currentVersionPosition == response.length() - 1) {
boolean isAtEnd = currentVersionPosition == response.length();
// If we're at end, and the End Version not equals Current Version
// >> deb Mode enabled
boolean isDev = isAtEnd && !interVersion.equals(currentVersion);
if (isDev) {
Log.d(TAG, "Hello Debluper");
Toast.makeText(context,
"Hello Debluper",
Toast.LENGTH_LONG).show();
} else if(isAtEnd) {
Log.d(TAG, "We're updated");
Toast.makeText(context,
"We're updated!",
Expand Down
29 changes: 15 additions & 14 deletions app/src/main/res/layout/update_message_view.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:orientation="vertical"
android:id="@+id/message_view"
android:layout_height="wrap_content">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<ScrollView android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView android:id="@+id/update_message"
<TextView
android:id="@+id/update_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="24dp"
Expand All @@ -19,24 +20,24 @@
</ScrollView>

<LinearLayout
android:id="@+id/progress_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="@+id/progress_view"
android:orientation="horizontal"
android:layout_height="wrap_content">
android:orientation="horizontal">

<ProgressBar
android:layout_gravity="center"
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"/>
android:layout_gravity="center"
android:padding="16dp" />

<TextView
android:padding="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fetching Changelog"/>
android:padding="16dp"
android:text="Fetching Changelog" />

</LinearLayout>

Expand Down
48 changes: 33 additions & 15 deletions app/src/main/res/xml/settings_preference_screen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,36 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<ListPreference
android:defaultValue="0"
android:entries="@array/theme_strings"
android:entryValues="@array/theme_values"
android:icon="@drawable/ic_style_black_24dp"
android:key="THEME_KEY"
android:summary="Select the base theme"
android:title="Theme" />

<CheckBoxPreference
android:defaultValue="false"
android:key="FRAG_SWITCHER_KEY"
android:summary="Current Switcher: Navigation Drawer"
android:title="Use BottomBar as Switcher" />
<PreferenceCategory
android:key="LOOK_AND_FEEL"
android:title="Look and Feel">

<ListPreference
android:defaultValue="0"
android:entries="@array/theme_strings"
android:entryValues="@array/theme_values"
android:icon="@drawable/ic_style_black_24dp"
android:key="THEME_KEY"
android:summary="Select the base theme"
android:title="Theme" />

<CheckBoxPreference
android:defaultValue="false"
android:key="FRAG_SWITCHER_KEY"
android:summary="Current Switcher: Navigation Drawer"
android:title="Use BottomBar as Switcher" />

</PreferenceCategory>

<PreferenceCategory
android:key="QOTD_CAT"
android:title="Quote of the Day">

<SwitchPreference
android:defaultValue="false"
android:key="QOTD_ENABLE"
android:summary="You'd be not receiving daily notifications"
android:title="Enable QoTD Notifications" />

<TimePickerPreference
android:key="QOTD_TIME"
Expand All @@ -24,6 +40,8 @@
android:title="Set time for QoTD"
app:pref_hourFormat="auto"
app:pref_pickerTime="10:10"
app:pref_summaryHasTime="QoTD will appear daily at %s" />
app:pref_summaryHasTime="Quote would appear at %s" />

</PreferenceCategory>

</PreferenceScreen>

0 comments on commit 82821c8

Please sign in to comment.