Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b3502150 authored by Veeti Paananen's avatar Veeti Paananen Committed by Ricardo Cerqueira
Browse files

Clean up, simplify and fix AlarmTile class and logic

This commit cleans up the AlarmTile class by removing the unnecessary
listener on the alarm intent. It now listens only to the next alarm
setting value, which was fetched after receiving the intent anyway.

These changes also fix a bug that would cause the tile to not show up
after some actions, like reordering the tiles due to the visibility not
being set on tile creation.

Lastly, some minor code styling issues have been fixed.

Patch set #2: collapse onNextAlarmChanged into onChangeUri, remove
mEnabled, use TextUtils to check for string emptiness and mark
updateQuickSettings explicitly as public.

Change-Id: Ic5871a9cc4874f33181dfac14e25a89499c182f2
parent 7a7d3494
Loading
Loading
Loading
Loading
+15 −29
Original line number Diff line number Diff line
package com.android.systemui.quicksettings;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Handler;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;

@@ -18,21 +17,14 @@ import com.android.systemui.statusbar.phone.QuickSettingsContainerView;

public class AlarmTile extends QuickSettingsTile {

    private boolean enabled = false;

    public AlarmTile(Context context, LayoutInflater inflater,
            QuickSettingsContainerView container,
            QuickSettingsController qsc, Handler handler) {
        super(context, inflater, container, qsc);

        mDrawable = R.drawable.ic_qs_alarm_on;
        String nextAlarmTime = Settings.System.getString(mContext.getContentResolver(), Settings.System.NEXT_ALARM_FORMATTED);
        if(nextAlarmTime != null){
            mLabel = nextAlarmTime;
        }

        mOnClick = new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
@@ -42,36 +34,30 @@ public class AlarmTile extends QuickSettingsTile{
                startSettingsActivity(intent);
            }
        };
        qsc.registerAction(Intent.ACTION_ALARM_CHANGED, this);

        qsc.registerObservedContent(Settings.System.getUriFor(
                Settings.System.NEXT_ALARM_FORMATTED), this);
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        onAlarmChanged(intent);
        updateStatus();
    }

    @Override
    public void onChangeUri(ContentResolver resolver, Uri uri) {
        onNextAlarmChanged();
        updateStatus();
        updateQuickSettings();
    }

    void onAlarmChanged(Intent intent) {
        enabled = intent.getBooleanExtra("alarmSet", false);
        updateQuickSettings();
    @Override
    public void updateQuickSettings() {
        mTile.setVisibility(!TextUtils.isEmpty(mLabel) ? View.VISIBLE : View.GONE);
        super.updateQuickSettings();
    }

    void onNextAlarmChanged() {
    /**
     * Updates the alarm status shown on the tile.
     */
    private void updateStatus() {
        mLabel = Settings.System.getString(mContext.getContentResolver(),
            Settings.System.NEXT_ALARM_FORMATTED);
        updateQuickSettings();
    }

    @Override
    void updateQuickSettings() {
        mTile.setVisibility(enabled ? View.VISIBLE : View.GONE);
        super.updateQuickSettings();
    }

}